package basic.java8;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;

/**
 * 流的筛选与切片
 */
public class StreamApiTest2 {

    List<Employee> employees = Arrays.asList(

        new Employee("张三",18,9999.99),
        new Employee("李四",58,5555.55),
        new Employee("王五",26,3333.33),
        new Employee("赵六",36,6666.66),
        new Employee("田七",12,8888.88)

    );

    /**
     * 筛选与切片
     * filter--接受Lambda
     * limit--截断流，使其元素不超过给定数量
     * skip(n)--跳过元素，返回一个扔到了前n个元素的流。若流中元素不足n个，则返回一个空流。与limit(n)互补
     * distinct --筛选，通过流所生成元素的hashCode()和equals()去除重复元素
     *
     */
    @Test
    public void test1(){
       employees.stream().filter((e)->e.getAge()>1)
                         .forEach(System.out::println);

    }
}